package com.neuedu.his.controller;


import com.neuedu.his.entity.Menu;
import com.neuedu.his.entity.Register;
import com.neuedu.his.entity.RegisterLevel;
import com.neuedu.his.framework.PageInfo;
import com.neuedu.his.framework.annotation.MethodAlias;
import com.neuedu.his.framework.servlet.BaseServlet;
import com.neuedu.his.service.MenuService;
import com.neuedu.his.service.RegisterLevelService;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;

/**
 * 项目：      his
 * 类名:       UserController
 * 创建时间：  2020/12/22  11:05
 * 描述 :
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */
@WebServlet(name = "RegistLevelController", urlPatterns = "/regist_level")
public class RegistLevelController extends BaseServlet {

    private RegisterLevelService registerLevelService = new RegisterLevelService();


    public void queryList(HttpServletRequest request, HttpServletResponse response) throws IOException {

        List<RegisterLevel> registerLevels = registerLevelService.queryList(request);
        //将结果以json格式返回
        this.success(response, registerLevels);
    }

    @MethodAlias("query")
    public void list(HttpServletRequest request, HttpServletResponse response) throws IOException {

        PageInfo pageInfo = registerLevelService.queryListByPage(request);
        //将结果以json格式返回
        this.success(response, pageInfo);
    }


    public void save(HttpServletRequest request, HttpServletResponse response) throws ParseException, NoSuchFieldException, IllegalAccessException, InstantiationException, IOException {

        RegisterLevel registerLevel = parseParameter(request, RegisterLevel.class);

        boolean success = false;
        if (registerLevel.getId() != null) { //修改
            success = registerLevelService.update(registerLevel);
        } else { //添加
            success = registerLevelService.save(registerLevel);
        }

        super.success(response, success);
    }

    public void toEdit(HttpServletRequest request, HttpServletResponse response) throws ParseException, NoSuchFieldException, IllegalAccessException, InstantiationException, IOException {

        String id = request.getParameter("id");

        RegisterLevel registerLevel = registerLevelService.queryById(Integer.parseInt(id));

        super.success(response, registerLevel);
    }


    public void del(HttpServletRequest request, HttpServletResponse response) throws ParseException, NoSuchFieldException, IllegalAccessException, InstantiationException, IOException {

        String id = request.getParameter("id");

        boolean success = registerLevelService.deleteById(Integer.parseInt(id));

        super.success(response, success);
    }


}